#include "BasePlayer.h"
#include "Params.h"
#include "TeamStates.h"
#include "Team.h"
#include <vector>

using namespace std;

void KickOff::Enter(Team *team)
{

}

void KickOff::Execute(Team* team)
{
	//If all players in position, we can start the game. 
	if (team->Game()->IsOn())
	{
		if( team->InControl())
		{
			team->GetFSM()->ChangeState(Attack::Istance());
		}
		else
		{
			team->GetFSM()->ChangeState(Defend::Istance());
		}
	}
		
}

void KickOff::Exit(Team *team)
{

}

bool KickOff::OnMessage(Team *team, const Telegram &)
{
	return true;
}

void Defend::Enter(Team *team)
{
	team->ChangeRegions( (team->Color()==Params::blue)? Params::BlueDefRegion : Params::RedDefRegion);
	
	team->SendPlayersToHome();
}

void Defend::Execute(Team* team)
{
	//if ball control is gained, go attack.
	if (team->InControl())
	{
		team->GetFSM()->ChangeState(Attack::Istance());
	}

}

void Defend::Exit(Team *team)
{

}

bool Defend::OnMessage(Team *team, const Telegram &)
{
	return true;
}

void Attack::Enter(Team *team)
{
	team->ChangeRegions( (team->Color()==Params::blue)? Params::BlueAttRegion: Params::RedAttRegion);
	
	team->SendPlayersToHome();
}

void Attack::Execute(Team* team)
{
	//if ball control is lost, move to defend state
	if(!team->InControl())
	{
		team->GetFSM()->ChangeState(Defend::Istance());
	}

}

void Attack::Exit(Team *team)
{

}

bool Attack::OnMessage(Team *team, const Telegram &)
{
	return true;
}